<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta http-equiv="X-UA-Compatible" content="IE=8">
		<title>修改密码 </title>
		<link href="../favicon.ico" rel="icon" type="image/x-icon" />
		<link rel="stylesheet" href="../../bootstrap/css/bootstrap.min.css">
		<link rel="stylesheet" href="../../layui/css/layui.css">
		<link rel="stylesheet" href="../../css/common.css">
		<link rel="stylesheet" href="../../css/default.css">
		<link rel="stylesheet" href="../../css/login.css">

		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js?version=1.01"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js?version=1.01"></script>
    <![endif]-->

	</head>

	<body>

		<!--头部-->
		<div class="layui-fluid">
			<div class="top_header_wrap"></div>
			<!--广告-->
			<div class="banner">
				<img src="../../img/banner.jpg" />
			</div>
			<!--登录框-->
			<div class="sign_guiding">
				———————&nbsp;&nbsp;高考报考指南&nbsp;&nbsp;———————
			</div>
			<div class="login_box">
				<div class="login_title">
					<strong>|</strong>修改密码
				</div>
				<div class="">
					<div class="form_wrapper">
					<span style="color:red;display:none;" id="msg">登录xx</span>
						<div class="layui-form-item">
							<div class="layui-input-block input_wrap">
								<input id="oldPassword" type="password" name="password" placeholder="请输入旧密码" required="required" autocomplete="off" class="layui-input">
								<!--<i class="icons-password"></i>-->
								<i class="icon iconfont login_icons"><img src="../../img/temp/password_icon.png"></i>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block input_wrap">
								<input id="newPassword" type="password" name="password" placeholder="请输入新密码" required="required" autocomplete="off" class="layui-input">
								<!--<i class="icons-password"></i>-->
								<i class="icon iconfont login_icons"><img src="../../img/temp/password_icon.png"></i>
							</div>
						</div>
						<div class="layui-form-item">
							<div class="layui-input-block input_wrap">
								<input id="repeatpassword" type="password" name="password" placeholder="请再次输入密码" required="required" autocomplete="off" class="layui-input">
								<!--<i class="icons-password"></i>-->
								<i class="icon iconfont login_icons"><img src="../../img/temp/password_icon.png"></i>
							</div>
						</div>
						<div id="confirm_btn" class="layui-form-item">
							<div class="loginHandle">
								<button class="layui-btn layui-input-login orange_bg" lay-submit="" lay-filter="demo1">确认</button>
							</div>
						</div>
						<div class="register_tips_text">
							<span class="orange_color"><<返回登录</span>
						</div>
					</div>
				</div>
			</div>
			<!--尾部-->
			<div class="footer_container">
				
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../js/jquery-1.11.0.min.js"></script>
	<script type="text/javascript" src="../../bootstrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../../js/md5.js"></script>
	<script type="text/javascript" src="../../layui/layui.all.js"></script>
	<script type="text/javascript" src="../../js/cookieUtils.js" ></script>
	<script>
		 $(document).ready(function(){
		   $(".top_header_wrap").load("../common/header.html");
		    $(".footer_container").load("../common/footer.html");
		    
		    
	   })
		$('#confirm_btn').click(function(){
			var oldPassword = $('#oldPassword').val();
			var newPassword = $('#newPassword').val();
			var repeatpassword = $('#repeatpassword').val();
			var pPattern = /^(\w){6,20}$/;
			
			
			if(oldPassword == null || oldPassword == '') {
				$('#msg').html("原始密码不能为空");
				$('#msg').show();
				$("#oldPassword").focus();
				return;
			}
			
			if(newPassword == null || newPassword == '') {
				$('#msg').html("新密码不能为空");
				$('#msg').show();
				$("#newPassword").focus();
				return;
			}
			if(repeatpassword == null || repeatpassword == '') {
				$('#msg').html("确认密码不能为空");
				$('#msg').show();
				$("#repeatpassword").focus();
				return;
			}
			if(newPassword != repeatpassword){
				$('#msg').html(" 您输入的确认密码与上次输入的不一致 ");
				$('#msg').show();
				return;
			}
				if(!(pPattern.test(oldPassword))) {
				$('#msg').html("只能输入6-20个字母、数字、下划线  ");
				$('#msg').show();
				return;
			}
			if(!(pPattern.test(newPassword))) {
				$('#msg').html("只能输入6-20个字母、数字、下划线  ");
				$('#msg').show();
				return;
			}
			if(!(pPattern.test(repeatpassword))) {
				$('#msg').html("只能输入6-20个字母、数字、下划线  ");
				$('#msg').show();
				return;
			}
			
			var data = {
				userId: GetCookie("userId"),
				oldPassword: oldPassword,
				newPassword: newPassword,
				repeatpassword:repeatpassword
			};
			console.log(data)
			$.ajax({
				type: "POST",
				url: "http://47.111.188.27:8080/gsgkzyl/user/modify",
				//contentType: "application/x-www-form-urlencoded; charset=UTF-8",
				xhrFields: {
                withCredentials:true
                 },
                crossDomain: true,
				data: data,
				success: function(pass) {
					console.log(pass)
					if(pass.status == 0) {
						layer.alert('密码修改成功', function() {
							window.location.href = "dynamic/news.html"
						})
							
					} else {
						$('#msg').show();
						$('#msg').html(pass.msg);

					}
				}
			});
		})
			
		

	</script>

</html>